package com.mc.utils;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.mc.model.login.LoginDto;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

public class CodeUtils {
    public static LoginDto getCode(){
       HttpResponse response = HttpUtil.createGet("http://work.okpss.cn:58080/inc/checkcode.jsp").execute();
       response.writeBody("/Users/happysmile/Documents/code/mc-auto-test/file/response.jpeg");
        File file = new File("/Users/happysmile/Documents/code/mc-auto-test/file/response.jpeg");
        ITesseract it = new Tesseract();
        it.setDatapath("/opt/language/");
        String result = null;
        try {
             result = it.doOCR(file);
            System.out.println("识别结果:"+result );
        } catch (TesseractException e) {
            e.printStackTrace();
        }
        LoginDto loginDto = LoginDto.builder()
                .vCode(result)
                .sessionId(response.getCookies().get(0).getName() + "=" + response.getCookies().get(0).getValue())
                .build();
        return loginDto;
    }


}
